package com.sgb.kjwl.view.ui.activity.enterprise;

import android.annotation.SuppressLint;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityTeamDetailUserCenterBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.model.entity.enterprise.UserServiceTeamDetailEntity;
import com.sgb.kjwl.viewmodel.enterprise.UserCenterTeamDetailModel;
import com.swgk.core.base.di.AppComponent;

import java.lang.reflect.Type;
import java.util.ArrayList;

import javax.inject.Inject;


public class UserCenterTeamDetailActivity extends AppActivity {

    private ActivityTeamDetailUserCenterBinding binding;

    @Inject
    UserCenterTeamDetailModel userCenterTeamDetailModel;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseComponent.builder().appComponent(appComponent)
                .enterpriseModule(new EnterpriseModule(this))
                .build()
                .inject(this);
    }

    //设置状态栏为暗
    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(UserCenterTeamDetailActivity.this, R.layout.activity_team_detail_user_center);

        binding.scrollView.setVisibility(View.INVISIBLE);
        binding.setModel(userCenterTeamDetailModel);
        binding.include.titleView.setText("基本信息");
        binding.include.ivBack.setVisibility(View.VISIBLE);
        binding.include.ivBack.setOnClickListener(view -> finish());

        userCenterTeamDetailModel.getTeamQueryDetailUserCenter();

        binding.setPtd(new UserServiceTeamDetailEntity());
    }


    @SuppressLint("SetJavaScriptEnabled")
    public void setShowDetails(UserServiceTeamDetailEntity entity) {
        binding.setPtd(entity);
        binding.scrollView.setVisibility(View.VISIBLE);
        String content = entity.getTeamDes();
        binding.webDescription.getSettings().setDefaultTextEncodingName("UTF-8");
        binding.webDescription.getSettings().setJavaScriptEnabled(true);//支持JS
        String js = "<script type=\"text/javascript\">" +
                "var imgs = document.getElementsByTagName('img');" + // 找到img标签
                "for(var i = 0; i<imgs.length; i++){" +  // 逐个改变
                "imgs[i].style.width = '100%';" +  // 宽度改为100%
                "imgs[i].style.height = 'auto';" +
                "}" +
                "</script>";
        binding.webDescription.loadDataWithBaseURL(null, content + js, "text/html", "UTF-8", null);

    }

}
